/**
 * Title : jFamilyTree
 * Description: jFamilyTree
 * About: Designed and rewritten by Andreas Lundgren, based on the Treebolic application suite
 * Copyright:	(c) 2001-2008
 * Terms of use:see license agreement at http://treebolic.sourceforge.net/en/license.htm
 * Author: Bernard Bou
 * Company: bsys
 */
package jFamilyTree.commons;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * About dialog
 * 
 * @author Bernard Bou
 */
public class AboutDialog extends JDialog
{
	private static final long serialVersionUID = 1L;

	/**
	 * Author
	 */
	static final String theAuthor = "Bernard Bou, bsys"; //$NON-NLS-1$

	/**
	 * Email
	 */
	static final String theEmail = "<bbou@ac-toulouse.fr>"; //$NON-NLS-1$

	/**
	 * Copyright notice
	 */
	static final String theCopyright = "Copyright (c) 2001-2008"; //$NON-NLS-1$

	/**
	 * Constructor
	 * 
	 * @param thisProduct
	 *        product
	 * @param thisVersion
	 *        string
	 */
	public AboutDialog(String thisProduct, String thisVersion)
	{
		initialize(thisProduct, thisVersion);
	}

	/**
	 * Initialize component
	 * 
	 * @param thisProduct
	 *        product
	 * @param thisVersion
	 *        string
	 */
	private void initialize(String thisProduct, String thisVersion)
	{
		setTitle(Messages.getString("AboutDialog.0")); //$NON-NLS-1$

		JLabel thisTitleLabel = new JLabel(thisProduct);
		thisTitleLabel.setFont(new Font("Dialog", Font.BOLD, 16)); //$NON-NLS-1$

		JLabel thisAuthorLabel = new JLabel(theAuthor);

		JLabel thisEmailLabel = new JLabel(theEmail);
		thisEmailLabel.setForeground(Color.BLUE);

		JLabel thisCopyrightLabel = new JLabel(theCopyright);
		JLabel thisVersionLabel = new JLabel(thisVersion);

		String theseProps = JavaVersion.getJavaPropsString();
		JTextArea thisJavaInfo = new JTextArea();
		thisJavaInfo.setEditable(false);
		thisJavaInfo.setText(theseProps);
		thisJavaInfo.setCaretPosition(0);
		thisJavaInfo.setLineWrap(false);

		JLabel thisImage = new JLabel();
		thisImage.setIcon(new ImageIcon(AboutDialog.class.getResource("images/logo.png"))); //$NON-NLS-1$

		JButton thisOKButton = new JButton(Messages.getString("AboutDialog.10")); //$NON-NLS-1$
		thisOKButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				setVisible(false);
			}
		});

		JPanel thisCommandPanel = new JPanel();
		thisCommandPanel.setLayout(new FlowLayout());
		thisCommandPanel.add(thisOKButton);

		JPanel thisPanel = new JPanel();
		thisPanel.setLayout(new GridBagLayout());
		thisPanel.add(thisTitleLabel, new GridBagConstraints(0, 0, 1, 1, 0., 0., GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 10, 0, 10), 0, 0));
		thisPanel.add(thisVersionLabel, new GridBagConstraints(0, 10, 1, 1, 0., 0., GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 10), 0, 0));
		thisPanel.add(thisImage, new GridBagConstraints(0, 11, 1, 1, 0., 0., GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0));
		thisPanel.add(thisAuthorLabel, new GridBagConstraints(0, 21, 1, 1, 0., 0., GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 10), 0, 0));
		thisPanel.add(thisEmailLabel, new GridBagConstraints(0, 22, 1, 1, 0., 0., GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 10), 0, 0));
		thisPanel.add(thisCopyrightLabel, new GridBagConstraints(0, 23, 1, 1, 0., 0., GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 10), 0, 0));	
		thisPanel.add(new JScrollPane(thisJavaInfo), new GridBagConstraints(0, 30, 1, 1, 1., 1., GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0));
		thisPanel.add(thisCommandPanel, new GridBagConstraints(0, 40, 1, 1, 0., 0., GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));

		setContentPane(thisPanel);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.Dialog#setVisible(boolean)
	 */
	@Override
	public void setVisible(boolean thisFlag)
	{
		if (thisFlag)
		{
			pack();
			Utils.center(this);
		}
		super.setVisible(thisFlag);
	}
}
